package com.ruoyi.web.ydz.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.ydz.domain.LiveBroadcast;
import com.ruoyi.web.ydz.mapper.LiveBroadcastMapper;
import com.ruoyi.web.ydz.service.ILiveBroadcastService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 直播记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-24
 */
@Service
public class LiveBroadcastServiceImpl implements ILiveBroadcastService
{
    @Resource
    private LiveBroadcastMapper liveBroadcastMapper;

    /**
     * 查询直播记录
     * 
     * @param id 直播记录主键
     * @return 直播记录
     */
    @Override
    public LiveBroadcast selectLiveBroadcastById(Long id)
    {
        return liveBroadcastMapper.selectLiveBroadcastById(id);
    }

    /**
     * 查询直播记录列表
     * 
     * @param liveBroadcast 直播记录
     * @return 直播记录
     */
    @Override
    public List<LiveBroadcast> selectLiveBroadcastList(LiveBroadcast liveBroadcast)
    {
        return liveBroadcastMapper.selectLiveBroadcastList(liveBroadcast);
    }

    /**
     * 新增直播记录
     * 
     * @param liveBroadcast 直播记录
     * @return 结果
     */
    @Override
    public int insertLiveBroadcast(LiveBroadcast liveBroadcast)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        liveBroadcast.setCreateTime(DateUtils.getNowDate());
        liveBroadcast.setCreateBy(user.getUserName());
        liveBroadcast.setCreateName(user.getNickName());

        liveBroadcast.setUpdateTime(DateUtils.getNowDate());
        liveBroadcast.setUpdateBy(user.getUserName());
        liveBroadcast.setUpdateName(user.getNickName());

        return liveBroadcastMapper.insertLiveBroadcast(liveBroadcast);
    }

    /**
     * 修改直播记录
     * 
     * @param liveBroadcast 直播记录
     * @return 结果
     */
    @Override
    public int updateLiveBroadcast(LiveBroadcast liveBroadcast)
    {

        SysUser user = SecurityUtils.getLoginUser().getUser();
        liveBroadcast.setUpdateTime(DateUtils.getNowDate());
        liveBroadcast.setUpdateBy(user.getUserName());
        liveBroadcast.setUpdateName(user.getNickName());

        return liveBroadcastMapper.updateLiveBroadcast(liveBroadcast);
    }

    /**
     * 批量删除直播记录
     * 
     * @param ids 需要删除的直播记录主键
     * @return 结果
     */
    @Override
    public int deleteLiveBroadcastByIds(Long[] ids)
    {
        return liveBroadcastMapper.deleteLiveBroadcastByIds(ids);
    }

    /**
     * 删除直播记录信息
     * 
     * @param id 直播记录主键
     * @return 结果
     */
    @Override
    public int deleteLiveBroadcastById(Long id)
    {
        return liveBroadcastMapper.deleteLiveBroadcastById(id);
    }

    /**
     * 获取最新一次直播记录
     *
     * @param
     * @return 结果
     */
    public LiveBroadcast selectMaxLiveBroadcast(){
        return liveBroadcastMapper.selectMaxLiveBroadcast();
    }
}
